extends Node2D


@onready var health_bar = $health_bar as ProgressBar
@onready var data_management = $data_management as DataManagement


#============================================================
#  内置
#============================================================
func _ready():
	data_management.newly_added_property.connect(_newly_added_property)
	data_management.property_changed.connect(_property_changed)
	data_management.set_property(PropertyConsts.HEALTH, 0)
	data_management.set_property(PropertyConsts.HEALTH_MAX, 10)


#============================================================
#  连接信号
#============================================================
func _newly_added_property(property, value):
	if property == PropertyConsts.HEALTH_MAX:
		health_bar.max_value = value


func _property_changed(property, previous, current):
	if property == PropertyConsts.HEALTH:
		health_bar.value = current


func _on_add_pressed():
	if data_management.get_property(PropertyConsts.HEALTH) < data_management.get_property(PropertyConsts.HEALTH_MAX):
		data_management.add_property(PropertyConsts.HEALTH, 1)


func _on_sub_pressed():
	if data_management.get_property(PropertyConsts.HEALTH) > 0:
		data_management.sub_property(PropertyConsts.HEALTH, 1)
